﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ReconocedorSonidosVocales
{
    public class InputLayer:Layer
    {
        public Double[] I;//When an input vector is presented to the network, it is first (optionally) preprocessed into complement coding form. The resulting vector, I, represents a point in the space.

        public int M;//M the size of layer F1
        public InputLayer(Double[] inputVector,bool codingComplement) {
            this.newInput(inputVector,codingComplement);
        }
        public InputLayer() { 
        }
        public InputLayer(int inputVectorSize, bool codingComplement)
        {
            if (codingComplement)
            {
                this.M = inputVectorSize * 2;//Therefore, the dimension M of layer F1 is the double of the input vector's dimension
                //I = this.preprocessIntoComplementCoding(inputVector);//When an input vector is presented to the network, it is first preprocessed into complement coding form. The resulting vector, I, represents a point in the space.

            }
            else
            {
                this.M = inputVectorSize;
        

            }

            this.neurons = new Neuron[M];

            for (int i = 0; i < this.M; i++)//The activity pattern on layer F1 is set equal to I
            {
                this.neurons[i] = new Neuron();
                //this.neurons[i].value = I[i];
            }
        }
        public void newInput(Double[] inputVector,bool codingComplement){
            if (codingComplement)
            {
                this.M = inputVector.Length * 2;//Therefore, the dimension M of layer F1 is the double of the input vector's dimension
                I = this.preprocessIntoComplementCoding(inputVector);//When an input vector is presented to the network, it is first preprocessed into complement coding form. The resulting vector, I, represents a point in the space.

            }
            else
            {
                this.M = inputVector.Length;
                I = inputVector;

            }

            this.neurons = new Neuron[M];

            for (int i = 0; i < this.M; i++)//The activity pattern on layer F1 is set equal to I
            {
                this.neurons[i] = new Neuron();
                this.neurons[i].value = I[i];
            }        
        }
        private Double[] preprocessIntoComplementCoding(Double[] inputVector)//The network uses a form of normalization called complement coding. The operation consists on taking the input vector and concatenating it with its complement.
        {//(0.8,0.6), its complement is (0.2,0.4)
            Double[] I = new Double[this.M];
            for (int i = 0; i < this.M / 2; i++ )
            {
                I[i] = inputVector[i];
            }
            for (int i = this.M / 2; i < this.M; i++)
            {
                I[i] = 1-inputVector[i - (this.M / 2)];
            }

            return I;
        }

        public override string ToString()
        {
            String activityPattern="";
            for (int i = 0; i < this.M; i++ )
            {
                activityPattern +="("+ this.neurons[i].value+")";
            }
            return activityPattern;
        }
    }

}
